package com.hawthorn.admin.controller.sysuser;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hawthorn.admin.service.sysuser.SysUserService;
import com.hawthorn.platform.annotation.MarkLog;
import com.hawthorn.platform.exception.BizCode;
import com.hawthorn.platform.utils.common.MyUtil;
import com.hawthorn.platform.utils.iassert.AssertMyUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * <p>todo 系统用户controller</p>
 *
 * @version v1.0.2
 * @author: andyten@tom.com | xukaixing@hotmail.com
 * @created: 2021/12/1 9:16 AM
 * @copyright: Copyright (c)  andyten
 */
@Api(tags = {"admin-sysuser"})
@RestController
@RequestMapping("/sysuser/")
@Slf4j
public class SysUserController
{
  @Resource
  SysUserService sysUserService;

  /**
   * <p>todo 查询用户信息</p>
   * @param params
   * @return: com.baomidou.mybatisplus.core.metadata.IPage<java.util.Map < java.lang.String, java.lang.Object>>
   * @date: 2022/7/1 15:53
   * @version: 1.0.1
   */
  @ApiOperation(value = "查询->全部用户信息", notes = "查询全部用户信息")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "params", value = "查询条件参数", dataTypeClass = String.class)
  })
  @PostMapping(value = "/findUsers")
  public IPage<Map<String, Object>> findUsers(@RequestBody String params)
  {
    Page<Map<String, Object>> page = new Page<>();
    String conditions = MyUtil.getConditionsWhere(params, page);
    return sysUserService.findUsers(page, conditions);
  }

  /**
   * <p>todo 查询用户信息</p>
   * @param params
   * @return: com.baomidou.mybatisplus.core.metadata.IPage<java.util.Map < java.lang.String, java.lang.Object>>
   * @date: 2022/7/1 15:53
   * @version: 1.0.1
   */
  @ApiOperation(value = "查询->全部用户信息", notes = "查询全部用户信息")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "params", value = "查询条件参数", dataTypeClass = String.class)
  })
  @PostMapping(value = "/findUsersList")
  public IPage<Map<String, Object>> findUsersList(@RequestBody String params)
  {
    Page<Map<String, Object>> page = new Page<>();
    String conditions = MyUtil.getConditionsWhere(params, page);
    return sysUserService.findUsersList(page, conditions);
  }

  /**
   * <p>todo 查询渠道用户信息</p>
   * @param params
   * @return: com.baomidou.mybatisplus.core.metadata.IPage<java.util.Map < java.lang.String, java.lang.Object>>
   * @date: 2022/7/1 15:53
   * @version: 1.0.1
   */
  @ApiOperation(value = "查询->渠道用户信息", notes = "查询渠道用户信息")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "params", value = "查询条件参数", dataTypeClass = String.class)
  })
  @PostMapping(value = "/findDealerUsers")
  public IPage<Map<String, Object>> findDealerUsers(@RequestBody String params)
  {
    Page<Map<String, Object>> page = new Page<>();
    String conditions = MyUtil.getConditionsWhere(params, page);
    return sysUserService.findDealerUsers(page, conditions);
  }

  @PostMapping(value = "/findImportUsers")
  public IPage<Map<String, Object>> findImportUsers(@RequestBody String params)
  {
    Page<Map<String, Object>> page = new Page<>();
    String conditions = MyUtil.getConditionsWhere(params, page);
    return sysUserService.findImportUsers(page, conditions);
  }

  /**
   * <p>todo 查询用户登录信息</p>
   *
   * @author: andy.ten@tom.com ｜ xukaixing@hotmail.com
   * @date: 2022/4/30 18:28
   * @version: 1.0.1
   */
  @ApiOperation(value = "查询用户登录信息", notes = "查询用户登录信息")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "params", value = "查询条件参数", dataTypeClass = String.class)
  })
  @PostMapping(value = "/findUserLoginInfo")
  public IPage<Map<String, Object>> findUserLoginInfo(@RequestBody String params)
  {
    Page<Map<String, Object>> page = new Page<>();
    String conditions = MyUtil.getConditionsWhere(params, page);
    return sysUserService.findUserLoginInfo(page, conditions);
  }

  /**
   * <p>todo 保存用户信息</p>
   *
   * @author: andyten@tom.com | xukaixing@hotmail.com
   * @date: 2021/11/14 9:39 PM
   * @version: 1.0.1
   */
  @ApiOperation(value = "保存->保存用户信息", notes = "插入用户信息")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "params", value = "保存参数", dataTypeClass = Map.class)
  })
  @MarkLog(value = "新增用户-[{0}]", param = "account")
  @PostMapping(value = "/saveUser")
  public Map<String, Object> saveUser(@RequestBody Map<String, Object> param)
  {
    return sysUserService.saveUser(param);
  }

  /**
   * <p>todo 更新用户信息</p>
   *
   * @author: andyten@tom.com | xukaixing@hotmail.com
   * @date: 2021/11/14 9:25 PM
   * @version: 1.0.1
   */
  @ApiOperation(value = "更新->更新用户信息", notes = "更新用户信息")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "id", value = "主键", dataTypeClass = Long.class),
      @ApiImplicitParam(name = "param", value = "更新参数", dataTypeClass = Map.class)
  })
  @MarkLog(value = "更新用户-[{0}]", param = "account")
  @PutMapping(value = "/updateUser/{id}")
  public Map<String, Object> updateUser(@PathVariable("id") Long id, @RequestBody Map<String, Object> param)
  {
    Map<String, Object> saveUser;

    saveUser = sysUserService.updateUser(id, param);
    return saveUser;
  }

  /**
   * <p>todo 导出用户信息</p>
   *
   * @author: andy.ten@tom.com
   * @date: 2021/12/25 4:39 PM
   * @version: 1.0.1
   */
  @ApiOperation(value = "导出->导出用户信息", notes = "导出用户信息")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "response", value = "response", dataTypeClass = HttpServletResponse.class),
      @ApiImplicitParam(name = "params", value = "params", dataTypeClass = String.class)
  })
  @PostMapping(value = "/exportUserData")
  public void exportUserData(HttpServletResponse response, @RequestBody Map<String, Object> param) throws IOException
  {
    AssertMyUtil.notNull(param, BizCode.VARIABLE_NOT_EMPTY, "param");
    sysUserService.exportUserData(response, "用户信息导出", param);
  }

  /**
   * todo 渠道用户导出
   * @param: null
   * @return: null
   * @author: GZY
   * @date: 2023/3/29 12:18
   * @LastAuthor:
   * @LastDate:
   * @Logic: 弹道 3480
   * @LastLogic:
   * @version: v1.0.1
   * Modification History:
   * Date            Author          Version         Description
   * -----------------------------------------------------------
   * 2023/3/29        GZY           v1.0.1            init
   */
  @ApiOperation(value = "导出->导出渠道用户信息", notes = "导出渠道用户信息")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "response", value = "response", dataTypeClass = HttpServletResponse.class),
      @ApiImplicitParam(name = "params", value = "params", dataTypeClass = String.class)
  })
  @PostMapping(value = "/exportDealerUserData")
  public void exportDealerUserData(HttpServletResponse response, @RequestBody Map<String, Object> param) throws IOException
  {
    AssertMyUtil.notNull(param, BizCode.VARIABLE_NOT_EMPTY, "param");
    sysUserService.exportUserData(response, "渠道用户信息导出", param);
  }

  /**
   * <p>todo 获取用户详细信息</p>
   * @author: guohao 2607728024@qq.com
   * @date: 2022/6/30 14:31
   * @version: 1.0.1
   */
  @ApiOperation(value = "个人中心->获取用户详细信息", notes = "获取用户详细信息")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "userId", value = "userId", dataTypeClass = String.class)
  })
  @GetMapping(value = "/getUserInfoById")
  public Map<String, Object> getUserInfoById(@RequestParam String userId)
  {
    AssertMyUtil.notEmpty(userId, BizCode.METHOD_ARGS_NOTNULL, "userId");
    return sysUserService.getUserInfoById(userId);
  }

  /**
   * <p>todo 更新用户状态</p>
   * @param params
   * @return: java.util.Map<java.lang.String, java.lang.Object>
   * @author: fengliye@expservice.com.cn
   * @date: 2022/7/4 10:11
   * @version: 1.0.1
   */
  @ApiOperation(value = "更新->更新用户状态", notes = "更新用户状态")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "params", value = "params", dataTypeClass = String.class)
  })
  @MarkLog(value = "更新用户状态-[{0}]", param = "account")
  @PostMapping(value = "/updateUserStatus")
  public Map<String, Object> updateUserStatus(@RequestBody Map<String, Object> params)
  {
    Long id = Long.parseLong(MyUtil.getValue(params.get("id")));
    Integer status = Integer.parseInt(MyUtil.getValue(params.get("status")));
    String rid = MyUtil.getValue(params.get("rid"));
    Long deptId = Long.parseLong(MyUtil.getValue(params.get("deptId")));
    return sysUserService.updateUserStatus(id, status, rid, deptId);
  }

  /**
   * <p>todo 通过用户主键查询用户信息</p>
   * @author: sunwanzhong
   * @date: 2023/4/13 11:49
   * @version: 1.0.1
   */
  @ApiOperation(value = "查询->通过用户主键查询用户信息", notes = "通过用户主键查询用户信息")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "params", value = "params", dataTypeClass = Map.class)
  })
  @PostMapping(value = "/selectUserInfoById")
  @MarkLog(value = "通过用户主键查询用户信息-[{0}]", param = "params")
  public Map<String, Object> selectUserInfoById(@RequestBody Map<String, Object> params)
  {
    return sysUserService.selectUserInfoById(params);
  }
}
